package com.nxmu.hire.controller;

import com.nxmu.hire.common.exception.ServiceException;
import com.nxmu.hire.common.util.ResponseResult;
import com.nxmu.hire.service.GradeCoefficientService;
import com.nxmu.hire.vo.GradeCoefficientReqVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@CrossOrigin(origins = "*",allowCredentials = "true")
@RestController
@RequestMapping(value = "/gradeCoefficient")
public class GradeCoefficientController {

    @Autowired
    private GradeCoefficientService gradeCoefficientService;

    @ApiOperation(value = "/添加评分标准系数")
    @PostMapping(value = "/addGradeCoefficient")
    public ResponseResult addGradeCoefficient(@Valid @RequestBody GradeCoefficientReqVo gradeCoefficientReqVo){
        try {
            gradeCoefficientService.save(gradeCoefficientReqVo);
        } catch (ServiceException e) {
            return ResponseResult.fail(e.getMessage());
        }
        return ResponseResult.success();
    }

    @ApiOperation(value = "/查询评分标准系数")
    @GetMapping(value = "/findGradeCoefficient")
    public ResponseResult findGradeCoefficient() {
        return ResponseResult.success(gradeCoefficientService.findLastGradeCoefficient());
    }

}
